<template>
  <div class="app-container">
    <el-form label-width="auto" style="max-width: 50%;margin:50px 0 0 25%;">
      <el-form-item label=" 登录账号:">
        <!-- <el-input v-model="param.username" /> -->
        <span>{{ param.username }}</span>

      </el-form-item>
      <el-form-item label="账号类型:">
        <!-- <el-input v-model="param.userType" disabled /> -->
        <span>{{ param.userType }}</span>
      </el-form-item>
      <!-- <el-form-item label="所属角色:">
        <span>{{ param.roleNames }}</span>
      </el-form-item> -->
      <!-- <el-form-item label="所属职位:">
        <span>{{ param.workPosition }}</span>
      </el-form-item> -->
      <!-- <el-form-item label="所属部门:">
        <span>{{ param.deptName }}</span>
      </el-form-item> -->
      <el-form-item label="员工姓名:">
        <!-- <el-input v-model="param.nickname" /> -->
        <span>{{ param.nickname }}</span>
      </el-form-item>
      <el-form-item label="手机号:">
        <!-- <el-input v-model="param.mobile" disabled /> -->
        <span>{{ param.mobile }}</span>
      </el-form-item>
      <el-form-item label="邮箱地址:">
        <!-- <el-input v-model="param.email" disabled /> -->
        <span>{{ param.email }}</span>
      </el-form-item>
      <!-- <el-form-item label="管理员身份证号:">
        <span>{{ param.identityNo }}</span>
      </el-form-item>
      <el-form-item label="管理员身份证有效期:">
        <span>{{ param.iDCardTime }}</span>
      </el-form-item>
      <el-form-item label="管理员身份证:">
        <img :src="param.identityPhoto" alt="" disabled>
      </el-form-item>
      <el-form-item label="认证有效期:">
        <span>{{ param.certificationTime }}</span>
      </el-form-item> -->

      <!-- <el-button type="primary" style="margin-left: 30%;" @click="saveData">保存</el-button> -->

    </el-form>
  </div>
</template>
<script lang="ts" setup>
import { reactive, onMounted } from 'vue'
import useUserStore from '@/store/modules/user'
import { saveUserInfo } from '@/api/enterpriseManage/index'
import { ElMessage, ElMessageBox } from "element-plus";
import { error } from 'console';

const userStore = useUserStore()

// const form = reactive({
//   name: '',
//   desc: ''
// })
const param = reactive({
  username: '',
  userType: '',
  roleNames: '',
  workPosition: '',
  deptName: '',
  nickname: '',
  mobile: '',
  email: '',
  identityNo: '',
  iDCardTime: '',
  identityPhoto: '',
  certificationTime: '',
  // 保存所需字段
  id: '',
  roleId: ''
})

onMounted(() => {
  const userInfo = userStore.getUser();
  param.username = userInfo.username;
  // 用户类型(1 - ROOT - 超级管理员  2 - ADMIN - 系统管理员  3 - GENERAL - 普通用户  4 - GUEST - 访问游客)
  if (userInfo.userType == '1') {
    param.userType = "超级管理员";
  } else if (userInfo.userType == '2') {
    param.userType = "系统管理员";
  } else if (userInfo.userType == '3') {
    param.userType = "普通用户";
  } else if (userInfo.userType == '4') {
    param.userType = "访问游客";
  }
  param.roleNames = userInfo.roleNames;
  param.workPosition = userInfo.workPosition;
  param.deptName = userInfo.deptName;
  param.nickname = userInfo.nickname;
  param.mobile = userInfo.mobile;
  param.email = userInfo.email;
  param.identityNo = userInfo.identityNo;
  if (userInfo.startTime && userInfo.endTime) {
    param.iDCardTime = userInfo.startTime + '~' + userInfo.endTime;
  }
  param.identityPhoto = userInfo.identityPhoto;
  if (userInfo.examineStartTime && userInfo.examineEndTime) {
    param.certificationTime = userInfo.examineStartTime + '~' + userInfo.examineEndTime;
  }

  param.id = userInfo.id;
  param.roleId = userInfo.roleId;
})


const saveData = () => {
  const data = {
    "userId": param.id,
    "username": param.username,
    "nickname": param.nickname,
    "roleId": param.roleId,
    // "deptName": param.deptName,
    // "workPosition": param.workPosition
  }
  saveUserInfo(JSON.stringify(data)).then(res => {
    console.log(res)
    ElMessage.success('保存成功')
  }, error => {
    ElMessage.error('保存失败')
  })
}

</script>
<style lang="scss" scoped></style>